package com.example.productdemo.demos.pojo;

import com.alibaba.fastjson.JSON;
import com.example.userdemo.demos.User;
import com.example.userdemo.demos.UserFeignService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: ProductController
 * @Description:
 * @Date 2024/01/29 13:13
 * @Author songshaoqiu
 **/
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    UserFeignService feignService;
    @GetMapping("/product")
    @GlobalTransactional(rollbackFor = Exception.class)
    public String info(@RequestParam("name")String name){
        System.out.println("事务id---------------------->" + RootContext.getXID());
        Product product = productService.getById(1);
        product.setProductName("productName"+name);
        productService.updateById(product);
        User user = feignService.updateUser(name);
        return JSON.toJSONString(user);
    }
}
